//
// Created by moonlight on 25-7-22.
//
#include <iostream>
#include <list>
#include <ctime>
using namespace std;
void PrintList(const list<int> &L) {
    for (list<int>::const_iterator it = L.begin(); it != L.end(); it++) {
        cout << *it << " ";
    }
    cout << endl;
}
void list_construct() {
    list<int> L1;
    L1.push_back(10);
    L1.push_back(20);
    L1.push_back(30);
    PrintList(L1);
    list<int> L2(L1.begin(), L1.end());
    PrintList(L2);
    list<int> L3(L2);
    PrintList(L3);
    list<int> L4(10.,1000);
    PrintList(L4);
}

void list_give_value() {
    list<int> L1;
    for (int i = 1; i <= 10; i++) {
        int num = rand() % 91+10;
        L1.push_back(num);
    }
    list<int> L2;
    L2 = L1;

    list<int> L3;
    L3.assign(std::next(L2.begin(),2), std::next(L2.begin(),7));
    PrintList(L3);
    list<int> L4;
    L4.assign(10, 100);
    L1.swap(L4);
}
void list_compare_test() {
    list<int> L1;
    for (int i = 1; i <= 10; i++) {
        int num = rand() % 91+10;
        L1.push_back(num);
    }
    if (L1.empty()) {
        cout << "List is empty" << endl;
    }else {
        cout << "List is sorted" << endl;
        cout << "元素个数->"<< L1.size() << endl;
    }
    L1.resize(30,1);
}
void list_insert_delete() {
    list<int> L1;
    for (int i = 1; i <= 10; i++) {
        int num = rand() % 91+10;
        if (i<=5) {
            L1.push_back(i);
        } else {
            L1.push_front(i);
        }
    }
    L1.pop_back();
    L1.pop_front();
    PrintList(L1);
    L1.insert(L1.end(), L1.begin(), L1.end());
    L1.insert((std::next(L1.begin(),5)), 666);
    PrintList(L1);
    list<int>::iterator it = L1.begin();
    L1.erase(++it);
    PrintList(L1);
    L1.remove(2);
    PrintList(L1);
    L1.clear();
    if (L1.empty()) {
        cout << "List is cleared" << endl;
    }
}
bool myCompare(int num1, int num2) {
    return num1 < num2;
}
void get_element() {
    list<int> L1;
    for (int i = 1; i <= 10; i++) {
        int num = rand() % 91+10;
        L1.push_back(num);
    }
    L1.reverse();//反转
    PrintList(L1);
    L1.sort(myCompare);//不支持随机访问的迭代器不能使用标准算法,内部提供
    PrintList(L1);
}
int main() {
    srand((unsigned int)time(NULL));
    get_element();
    return 0;
}
